const {
    Mysql
} = require('../tools/utils');
module.exports = async (ctx) => {
    let {
        currentPage,
        pageSize,
        uid
    } = ctx.query;
    if (uid) {
        let sql = `SELECT orderList.*,cSessionInfo.user_info FROM orderList RIGHT JOIN cSessionInfo ON orderList.uid=cSessionInfo.uid WHERE orderList.uid=${!isNaN(Number(uid))?uid:0}`;
        try {
            let list = await Mysql(sql);
            ctx.state.data = {
                list
            }
        } catch (error) {};
        return;
    }
    let totalSql = `SELECT COUNT(*) FROM orderList`
    let sql = `SELECT * FROM orderList ORDER BY create_time DESC LIMIT ${(currentPage-1)*pageSize},${pageSize}`;
    try {
        try {
            let list = await Mysql(sql);
            let total = await Mysql(totalSql);
            ctx.state.data = {
                total: Object.values(total[0])[0],
                list
            }
        } catch (error) {
            ctx.state.data = {
                list: []
            }
        }
    } catch (error) {}
}